﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
#if NET40
using Microsoft.Practices.ServiceLocation;
#else
using CommonServiceLocator;
#endif

namespace Log.Common
{
    public static class LogHelper
    {
        public static void Info(string message, bool isWriteCaller = false, [CallerMemberName] string memberName = "",
            [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            GetLog()?.Info(message, isWriteCaller,memberName, sourceFilePath, sourceLineNumber);
        }

        public static void Error(Exception ex, bool isWriteCaller = true, [CallerMemberName] string memberName = "",
            [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            GetLog()?.Error(ex,isWriteCaller, memberName, sourceFilePath, sourceLineNumber);
        }

        public static void Error(string message, Exception ex, bool isWriteCaller = true, [CallerMemberName] string memberName = "",
            [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            GetLog()?.Error(message, ex, isWriteCaller,memberName, sourceFilePath,sourceLineNumber);
        }

        private static ILog GetLog()
        {
            try
            {
               return ServiceLocator.Current.GetInstance<ILog>();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return null;
            }
        }
    }
}
